<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceInviteGuestForEvent extends core {

    public function process() {
        $user_id = intval($_POST['user_id']);
        $arr_guest_list = $_POST['guest_list'];
        $event_id = intval($_POST['event_id']);
        $event = $this->db->get_row("SELECT * FROM events WHERE event_id=$event_id AND `user_id`='$user_id'");
        if ($event) {
            foreach ($arr_guest_list as $guest_id) {
                $guest_id = $this->db->escape($guest_id);
                $query = 'INSERT INTO guest_event (guest_id,event_id,attend) VALUES (' . $guest_id . ',' . $event_id . ',0);';
                $this->db->query($query);
            }

            $this->_JSONResponse(array('error' => 0, 'msg' => 'Guests have been added to the event'));
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => "Guests have not been added to the event!"));
        }
    }

}

$processor = new webServiceInviteGuestForEvent();
$processor->process();
?>